package com.zzq.base.awesome.controller;

import com.fasterxml.jackson.databind.util.ISO8601DateFormat;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.text.DateFormat;
import java.text.ParseException;
import java.time.format.DateTimeFormatter;
import java.util.*;


public class IgnoreUrlList {

    public static void main(String[] args) throws ParseException {
        String a = "2020-02-14T15:42:20.683Z";
        String pattern = "YYYY-MM-dd'T'HH:mm:ss.S'Z'";
        System.out.println(DateFormatUtils.format(new Date(), pattern));
        DateFormat parser2 = ISO8601DateFormat.getDateInstance();
        String jtdate = "2010-01-01T12:00:00+01:00";
        System.out.println(parser2.parse(a));
    }

    private static final Log logger = LogFactory.getLog(IgnoreUrlList.class);
    private static Set<String> urlsSet = new HashSet<>();
    private static List<String> urlsList = new ArrayList<>();

    private static void addSet(String s) {
        logger.info("添加忽略验证路由: " + s);
        urlsSet.add(s);
    }

    private static void addListStater(String s) {
        logger.info("添加忽略验证路由: " + s);
        urlsList.add(s);
    }

    public static void init() {
        addSet("/favicon.ico");
        addSet("/common/test");
        addSet("/api/user/login");
        addSet("/api/user/register");
        addListStater("/record");
        addListStater("/static/");
        addSet("/upload");
        addSet("/index");
    }

    public static boolean setContains(String url) {
        return urlsSet.contains(url);
    }

    public static boolean listHaveStarter(String url) {
        for (String s : urlsList) {
            if (url.startsWith(s)) {
                return true;
            }
        }
        return false;
    }
}
